package com.ruoyi.mall.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.domain.MallDistributionConfig;
import com.ruoyi.mall.service.IMallDistributionConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分销设置Controller
 * 
 * @author ruoyi
 * @date 2022-02-25
 */
@RestController
@RequestMapping("/mall/mallDistributionConfig")
public class MallDistributionConfigController extends BaseController
{
    @Autowired
    private IMallDistributionConfigService mallDistributionConfigService;

    /**
     * 查询分销设置列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallDistributionConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallDistributionConfig mallDistributionConfig)
    {
        startPage();
        List<MallDistributionConfig> list = mallDistributionConfigService.selectMallDistributionConfigList(mallDistributionConfig);
        return getDataTable(list);
    }

    /**
     * 导出分销设置列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallDistributionConfig:export')")
    @Log(title = "分销设置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallDistributionConfig mallDistributionConfig)
    {
        List<MallDistributionConfig> list = mallDistributionConfigService.selectMallDistributionConfigList(mallDistributionConfig);
        ExcelUtil<MallDistributionConfig> util = new ExcelUtil<MallDistributionConfig>(MallDistributionConfig.class);
        return util.exportExcel(list, "分销设置数据");
    }

    /**
     * 获取分销设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallDistributionConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallDistributionConfigService.selectMallDistributionConfigById(id));
    }

    /**
     * 新增分销设置
     */
    @PreAuthorize("@ss.hasPermi('mall:mallDistributionConfig:add')")
    @Log(title = "分销设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallDistributionConfig mallDistributionConfig)
    {
        return toAjax(mallDistributionConfigService.insertMallDistributionConfig(mallDistributionConfig));
    }

    /**
     * 修改分销设置
     */
    @PreAuthorize("@ss.hasPermi('mall:mallDistributionConfig:edit')")
    @Log(title = "分销设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallDistributionConfig mallDistributionConfig)
    {
        return toAjax(mallDistributionConfigService.updateMallDistributionConfig(mallDistributionConfig));
    }

    /**
     * 删除分销设置
     */
    @PreAuthorize("@ss.hasPermi('mall:mallDistributionConfig:remove')")
    @Log(title = "分销设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallDistributionConfigService.deleteMallDistributionConfigByIds(ids));
    }
}
